﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Serialization;
using TheDealmap.Enum;
using TheDealmap.Util;

namespace TheDealmap.Data
{
    /// <summary>
    /// Represents a returned deal.
    /// </summary>
    [Serializable]
    public class Deal
    {
        private int _activity = 0;
        private CenterdActivity _act;
        private Capability _cap;
        private int _capability = 0;

        /// <summary>
        /// Gets the activity. Ignored in serialization
        /// </summary>
        /// <value>The activity.</value>
        [XmlIgnore]
        public CenterdActivity Activity
        {
            get
            {
                return _act;
            }
        }
        /// <summary>
        /// Gets the capability. Ignored in serialization
        /// </summary>
        /// <value>The capability.</value>
        [XmlIgnore]
        public Capability Capability
        {
            get
            {
                return _cap;
            }
        }


        /// <summary>
        /// Gets or sets the activity integer value. This value is an integer for an enum representation please see <see cref="Activity"/> for an enum value.
        /// </summary>
        /// <value>The act.</value>
        [XmlElement("Activity")]
        public int Act
        {
            get { return _activity; }
            set 
            { 
                _activity = value;
                CFlagsExtracter<CenterdActivity> flager = new CFlagsExtracter<CenterdActivity>(_activity);
                IList<Enum.CenterdActivity> list = flager.aeFlags;
                if (list.Count == 0)
                    _act = CenterdActivity.Unknown;
                else
                    _act =  flager.aeFlags.Aggregate((a, b) => a |= b);
            }
        }
        /// <summary>
        /// Gets or sets the added by.
        /// </summary>
        /// <value>The added by.</value>
        public string AddedBy { get; set; }
        /// <summary>
        /// Gets or sets the additional discount coupon code.
        /// </summary>
        /// <value>The additional discount coupon code.</value>
        public string AdditionalDiscountCouponCode { get; set; }
        /// <summary>
        /// Gets or sets the additional discount coupon effective time.
        /// </summary>
        /// <value>The additional discount coupon effective time.</value>
        public DateTime AdditionalDiscountCouponEffectiveTime { get; set; }
        /// <summary>
        /// Gets or sets the additional discount coupon expiration time.
        /// </summary>
        /// <value>The additional discount coupon expiration time.</value>
        public DateTime AdditionalDiscountCouponExpirationTime { get; set; }
        /// <summary>
        /// Gets or sets the additional discount deal unit.
        /// </summary>
        /// <value>The additional discount deal unit.</value>
        public string AdditionalDiscountDealUnit { get; set; }
        /// <summary>
        /// Gets or sets the additional discounted value.
        /// </summary>
        /// <value>The additional discounted value.</value>
        public string AdditionalDiscountedValue { get; set; }
        /// <summary>
        /// Gets or sets the address line.
        /// </summary>
        /// <value>The address line.</value>
        public string AddressLine { get; set; }
        /// <summary>
        /// Gets or sets the affiliation.
        /// </summary>
        /// <value>The affiliation.</value>
        public string Affiliation { get; set; }
        /// <summary>
        /// Gets or sets the B description.
        /// </summary>
        /// <value>The B description.</value>
        public string BDescription { get; set; }
        /// <summary>
        /// Gets or sets the business ID.
        /// </summary>
        /// <value>The business ID.</value>
        public string BusinessID { get; set; }
        /// <summary>
        /// Gets or sets the name of the business.
        /// </summary>
        /// <value>The name of the business.</value>
        public string BusinessName { get; set; }
        /// <summary>
        /// Gets or sets the capabailiat value. This value is an integer for an enum representation please see <see cref="Capability"/> for an enum value.
        /// </summary>
        /// <value>The cap.</value>
        [XmlElement("Capability")]
        public int Cap { get { return _capability; } 
            set 
            { 
                _capability = value;
                CFlagsExtracter<Capability> flager = new CFlagsExtracter<Capability>(_capability);
                IList<Enum.Capability> list = flager.aeFlags;
                if ( list.Count == 0)
                    _cap = Capability.Unknown;
                else
                    _cap = flager.aeFlags.Aggregate((a, b) => a |= b);
            } 
        }
        /// <summary>
        /// Gets or sets the category.
        /// </summary>
        /// <value>The category.</value>
        public string Category { get; set; }
        /// <summary>
        /// Gets or sets the city.
        /// </summary>
        /// <value>The city.</value>
        public string City { get; set; }
        /// <summary>
        /// Gets or sets the country.
        /// </summary>
        /// <value>The country.</value>
        public string Country { get; set; }
        /// <summary>
        /// Gets or sets the currency.
        /// </summary>
        /// <value>The currency.</value>
        public string Currency { get; set; }
        /// <summary>
        /// Gets or sets the deal source.
        /// </summary>
        /// <value>The deal source.</value>
        public string DealSource { get; set; }
        /// <summary>
        /// Gets or sets the type of the deal.
        /// </summary>
        /// <value>The type of the deal.</value>
        public string DealType { get; set; }
        /// <summary>
        /// Gets or sets the deal unit.
        /// </summary>
        /// <value>The deal unit.</value>
        public string DealUnit { get; set; }
        /// <summary>
        /// Gets or sets the description.
        /// </summary>
        /// <value>The description.</value>
        public string Description { get; set; }
        /// <summary>
        /// Gets or sets the discounted value.
        /// </summary>
        /// <value>The discounted value.</value>
        public string DiscountedValue { get; set; }
        /// <summary>
        /// Gets or sets the effective time.
        /// </summary>
        /// <value>The effective time.</value>
        public DateTime EffectiveTime { get; set; }
        /// <summary>
        /// Gets or sets the expiration time.
        /// </summary>
        /// <value>The expiration time.</value>
        public DateTime ExpirationTime { get; set; }
        /// <summary>
        /// Gets or sets the face value.
        /// </summary>
        /// <value>The face value.</value>
        public string FaceValue { get; set; }
        /// <summary>
        /// Gets or sets the ID.
        /// </summary>
        /// <value>The ID.</value>
        public string ID { get; set; }
        /// <summary>
        /// Gets or sets the icon URL.
        /// </summary>
        /// <value>The icon URL.</value>
        public string IconUrl { get; set; }
        /// <summary>
        /// Gets or sets the image URL.
        /// </summary>
        /// <value>The image URL.</value>
        public string ImageUrl { get; set; }
        /// <summary>
        /// Gets or sets the keywords.
        /// </summary>
        /// <value>The keywords.</value>
        public string Keywords { get; set; }
        /// <summary>
        /// Gets or sets the latitude.
        /// </summary>
        /// <value>The latitude.</value>
        public string Latitude { get; set; }
        /// <summary>
        /// Gets or sets the longitude.
        /// </summary>
        /// <value>The longitude.</value>
        public string Longitude { get; set; }
        /// <summary>
        /// Gets or sets the more info link.
        /// </summary>
        /// <value>The more info link.</value>
        public string MoreInfoLink { get; set; }
        /// <summary>
        /// Gets or sets the phone.
        /// </summary>
        /// <value>The phone.</value>
        public string Phone { get; set; }
        /// <summary>
        /// Gets or sets the state.
        /// </summary>
        /// <value>The state.</value>
        public string State { get; set; }
        /// <summary>
        /// Gets or sets the tags.
        /// </summary>
        /// <value>The tags.</value>
        public string Tags { get; set; }
        /// <summary>
        /// Gets or sets the terms.
        /// </summary>
        /// <value>The terms.</value>
        public string Terms { get; set; }
        /// <summary>
        /// Gets or sets the title.
        /// </summary>
        /// <value>The title.</value>
        public string Title { get; set; }
        /// <summary>
        /// Gets or sets the tracking URL.
        /// </summary>
        /// <value>The tracking URL.</value>
        public string TrackingUrl { get; set; }
        /// <summary>
        /// Gets or sets the transaction URL.
        /// </summary>
        /// <value>The transaction URL.</value>
        public string TransactionUrl { get; set; }
        /// <summary>
        /// Gets or sets you save.
        /// </summary>
        /// <value>You save.</value>
        public string YouSave { get; set; }
        /// <summary>
        /// Gets or sets the zip code.
        /// </summary>
        /// <value>The zip code.</value>
        public string ZipCode { get; set; }
    }
}
